<template>
  <div>
    <van-nav-bar
      title="搜索页"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-search
      v-model="name"
      show-action
      placeholder="请输入搜索影片名称"
      @search="onSearch"
      @cancel="onCancel"
      @input="getMovie"
    />
    <div>
      <van-card
        v-for="item in movieAll"
        :key="item.id"
        :desc="item.Introduction"
        :title="item.name"
        :thumb="item.posters"
      >
        <template #bottom>
          类型：<van-tag type="warning">{{ item.category }}</van-tag>
        </template>
        <template #footer>
          <van-button
            round
            type="info"
            size="small"
            color="linear-gradient(to right, #9b9483, #77664e)"
            @click="toDetails(item.id)"
            >购买</van-button
          >
        </template>
      </van-card>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: "",
      movieAll:[]
    };
  },
  methods: {
    onClickLeft() {
      this.$router.back();
    },
    onSearch(val) {
      this.$message(val);
    },
    onCancel() {
      this.movieAll = []
      this.$message("取消");
    },
    async getMovie() {
      if( this.name.trim()===''){
        this.movieAll = []
        this.name=''
        return;
      }
      const {data:res} = await this.$http.get('search?name='+this.name.trim())
      if (res.status !== 200) return this.$message.fail("未查到该电影");
      this.movieAll = res.data
    },
     toDetails(id) {
      this.$router.push({
        path: `/details/${id}`,
      });
    },
  },
};
</script>

<style lang="less" scoped>
.van-card__desc {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  max-height:60px;
}
.van-ellipsis{
  white-space: normal ;
}
</style>